//
//  BKMyOrderDerTableviewCellHederAndFooter.m
//  bestkeep
//
//  Created by Mr. Wu on 16/12/12.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderDerTableviewCellHederAndFooter.h"




#import "BK_OD_Color.h"
#import "BK_OD_Tool.h"

//事件交互Btn的高度
#define HEIGHT_Btn_right  27
//事件交互Btn的宽度
#define WIDTH_Btn_right  149/2.0
//事件交互Btn的下半部分视图高度
#define HEIGHT_Footer_Down  44
#define BORDERWIDTH         0.6 //边框宽度
#define CORNERRADIUS        5  //圆角


#define COLOR_ORDER_DETAIL_Line RGB(218, 218, 218)
#define BACKCOLOR_BTN       [UIColor whiteColor] //按钮背景颜色
#define FONT_BTN            13.0 //按钮font


#define HEIGHT_FOOTER_UP_TWO    70.0
#define HEIGHT_FOOTER_DOWN      44.0
#define HEIGHT_FOOTER_UP_ONE    44.0



#define  Color_BKOrderDetailVC_BACK    RGB(242, 242, 242)


//S
#define  FONT_ORDER_Detail_S  12.0

//M
#define  FONT_ORDER_Detail_M  13.0

//主题字体
#define  FONT_ORDER_Detail_ZHUTI  14.0

//XL
#define  FONT_ORDER_Detail_XL  15.0

//XXL
#define  FONT_ORDER_Detail_XXL  16.0

//金钱字体
#define  FONT_ORDER_Detail_MONEY  15.0



@implementation BKMyOrderDerTableviewCellHederAndFooter

-(void)fillData:(id)data{
    
}
@end


/*
 * 订单详情    XX发货
 */
@implementation BKMyOrderTableviewCellHeder

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    
    return self;
    
}
-(void)initView{
    
    _addressView =[UIView new];
    _addressView.backgroundColor=[UIColor whiteColor];
    [self addSubview:_addressView];
    [_addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    /**
     *  位置图片
     */
    _ImgV_Address=[[UIImageView alloc]init];
    [self addSubview:_ImgV_Address];
    _ImgV_Address.image=[UIImage imageNamed:@"订单-发货地icon"];
    [_ImgV_Address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.left.equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.height.equalTo(@(12));
        make.width.equalTo(@(14));
    }];
    
    _addresLabel =[UILabel new];
    _addresLabel.textColor = kOrderBlack1;
    _addresLabel.font =[UIFont systemFontOfSize:14.0];
    [self addSubview:_addresLabel];
    [_addresLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_ImgV_Address.mas_right).mas_offset(10);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
}
-(void)fillData:(id)data{
    BK_My_DetailOrder_SectionModel *model = data;
    BK_My_DetailOrder_Model *_centerModel = model.Ordermodel;
    if (_centerModel.ship_address) {
        _addresLabel.text=[NSString stringWithFormat:@"%@发货",_centerModel.ship_address];
    }
}

@end

@implementation BKMyOrderDerTableviewCellFooter


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
        
    }
    return self;
}
- (void)initView{
    
      //分割线
    UIView* view_line=[[UIView alloc]init];
    view_line.backgroundColor=COLOR_ORDER_DETAIL_Line;
    [self addSubview:view_line];
    [view_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left);
        make.top.mas_equalTo(self.mas_top);
        make.height.mas_equalTo(@(0.7));
    }];
    
    // 共1件商品 合计：￥0.00（含运费￥0.00）
    
    _lab_detail=[[UILabel alloc]init];
    _lab_detail.textColor = kOrderBlack1;
    _lab_detail.font = [UIFont systemFontOfSize:FONT_ORDER_Detail_ZHUTI];
    _lab_detail.text = @"共1件商品 合计：￥0.00(含运费￥0.00)";
    [self addSubview:_lab_detail];
    _lab_detail.textAlignment=NSTextAlignmentRight;
    //明细按钮;
    
    _btn_showDetail =[[UIButton alloc]init];
    [self addSubview:_btn_showDetail];
    [_btn_showDetail addTarget:self action:@selector(show_btn:) forControlEvents:UIControlEventTouchUpInside];
    _ImgV_showDetail=[[UIImageView alloc]init];
    _ImgV_showDetail.image=[UIImage imageNamed:@"Imported Layers Copy"];
    [_btn_showDetail addSubview:_ImgV_showDetail];
    /**
     *  实际付款金额;
     */
    _lab_payPrice = [UILabel new];
    _lab_payPrice.textColor =  kOrderBlack1;;
    _lab_payPrice.text = @"￥---";
    _lab_payPrice.font = [UIFont boldSystemFontOfSize:FONT_ORDER_Detail_XXL];
    _lab_payPrice.textAlignment=NSTextAlignmentRight;
    [self addSubview:_lab_payPrice];
    
    
    // 分割线
    
    _view_line=[[UIView alloc]init];
    _view_line.backgroundColor=COLOR_ORDER_DETAIL_Line;
    [self addSubview:_view_line];
    [_view_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-HEIGHT_FOOTER_DOWN);
        make.height.mas_equalTo(@(0.7));
    }];
    
    
    /**
     *  下半部分视图
     */
    _view_down=[[UIView alloc]init];
    _view_down.backgroundColor=[UIColor whiteColor];
    [self addSubview:_view_down];
    [_view_down mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left);
        make.top.mas_equalTo(_view_line.mas_bottom);
        make.height.mas_equalTo(@(HEIGHT_Footer_Down));
    }];
    self.bottomView = [BKMyOrderBottomView new];
    [_view_down addSubview:self.bottomView];
    
    [self.bottomView.btn_right_one addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView.btn_right_two addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.bottomView.btn_right_three addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.bottomView.btn_right_four addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_view_down.mas_right);
        make.left.mas_equalTo(_view_down.mas_left);
        make.top.mas_equalTo(_view_down.mas_top);
        make.bottom.mas_equalTo(_view_down.mas_bottom);
    }];
    
    
    
}
-(void)fillData:(id)data{
    BK_My_DetailOrder_SectionModel *section = data;
    
    BK_My_DetailOrder_Model *cenM = section.Ordermodel;
    self.orderModel = cenM;
    //共%@件商品 合计：%@(含运费￥%@)
    if (cenM.order_total_amount&&cenM.express_amount) {
        //运费
        NSString * str_expressAmountS=[NSString stringWithFormat:@"%.2f",[cenM.express_amount floatValue]];
        //付款金额
        NSString * str_total_amount=[NSString stringWithFormat:@"￥%@",cenM.order_total_amount];
        NSString *  str_lab_detail=[NSString stringWithFormat:@"共%@件商品 合计：%@(含运费￥%@)",cenM.order_goods_count,str_total_amount,str_expressAmountS];
        
        NSMutableAttributedString *attri_lab_detail =[[NSMutableAttributedString alloc] initWithString:str_lab_detail];
        
        NSRange range = [str_lab_detail rangeOfString:  str_total_amount];
        [attri_lab_detail addAttribute:NSForegroundColorAttributeName value:kOrderPriceRed range:range];
        [attri_lab_detail addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:range];
        _lab_detail.attributedText = attri_lab_detail;
    }
    
    //实际付款;
    if (cenM.actualPaymentAmount) {
        NSString *Actually = [NSString stringWithFormat:@"¥%.2f",[cenM.actualPaymentAmount floatValue]];
        NSString *detailActually = [NSString stringWithFormat:@"实际付款:   %@",Actually];
        NSMutableAttributedString *attri_Actually =[[NSMutableAttributedString alloc] initWithString:detailActually];
        
        NSRange range = [detailActually rangeOfString:Actually];
        NSRange range1 = [detailActually rangeOfString:@"实际付款:"];
        
        [attri_Actually addAttribute:NSForegroundColorAttributeName value:kOrderPriceRed range:range];
        //钱数比实际付款大一号;
        [attri_Actually addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:range];
        [attri_Actually addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:range1];
        _lab_payPrice.attributedText = attri_Actually;
    }
    self.bottomView.order_model = cenM;
    
    [self relayContstraints:cenM];
    
    
}


#pragma ============= delegate
-(void)click_Button:(UIButton *)btn{
    if ([self.sectiondelegate respondsToSelector:@selector(BKOrderFooterViewDelegate_ClickBtn:)]) {
        [self.sectiondelegate BKOrderFooterViewDelegate_ClickBtn:btn];
        
    }
}

-(void)show_btn:(UIButton *)btn{
    
    btn.selected = !btn.selected;
    [self relayContstraints:self.orderModel];
    if ([self.sectiondelegate respondsToSelector:@selector(BKOrderFooterViewDelegate_ShowBtn:)]) {
        [self.sectiondelegate BKOrderFooterViewDelegate_ShowBtn:self.footHeight];
    }
}

-(void)relayContstraints:(BK_My_DetailOrder_Model*)model{
    BOOL ShowActually;
    BOOL ShowDetailBtn;
    
    ShowActually=NO;
    ShowDetailBtn=NO;
    
    NSMutableArray *array = [NSMutableArray array];
    //显示明细的数量;
    for (BK_My_DetailOrder_payAmountDetail_Model *list in model.payAmountDetail) {
        if(list){
            if (![list.itemAmountStr isEqualToString:@"0.00"]) {
                [array addObject:list];
                
            }
        }
    }
    //明细的高;
    CGFloat height = array.count *30 + 20;
    NSString *stutus = model.order_status;
    if (!_discountView) {
        _discountView  = [[BKMyOrderDiscountView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, height)];
        _discountView.backgroundColor = [UIColor grayColor];
        _discountView.model = model;
        
        [self addSubview:_discountView];
    }
    if ([stutus isEqualToString:@"02"]||[stutus isEqualToString:@"03"]||[stutus isEqualToString:@"04"]) {
        ShowActually = YES;//显示实际付款
        if (array.count) {
            ShowDetailBtn = YES;//显示明细;
        }
    }
    //不显示实际付款
    if (!ShowActually) {
        _btn_showDetail.hidden = YES;
        _lab_payPrice.hidden = YES;
        _discountView.hidden = YES;
    }
    //显示实际付款但没有明细;
    if (ShowActually &&(!ShowDetailBtn)) {
        _btn_showDetail.hidden = YES;
        _discountView.hidden = YES;
    }
    if (_btn_showDetail.selected) {
        self.footHeight = 114 +height;
    }
    else{
        self.footHeight = 114;
    }
    
    
    [_lab_detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
        make.top.mas_equalTo(self.mas_top).mas_offset(1);
        make.height.mas_equalTo(@(HEIGHT_FOOTER_UP_ONE));
    }];
    [_btn_showDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge+10);
        make.bottom.mas_equalTo(self.mas_top).offset(64);
        make.height.mas_equalTo(@(30));
        make.width.mas_equalTo(@(30));
    }];
    [_ImgV_showDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_btn_showDetail.mas_centerX);
        make.centerY.mas_equalTo(_btn_showDetail.mas_centerY);
        make.height.mas_equalTo(@(7));
        make.width.mas_equalTo(@(10));
    }];
    if (ShowDetailBtn) {
        [_lab_payPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.mas_equalTo(self.btn_showDetail.mas_right).offset(-30);
            
            make.bottom.mas_equalTo(self.mas_top).offset(64);
            
            make.height.mas_equalTo(@(30));
        }];
    }
    if (!ShowDetailBtn) {
        [_lab_payPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
            make.bottom.mas_equalTo(self.mas_top).offset(64);
            make.height.mas_equalTo(@(30));
        }];
    }
    if (_btn_showDetail.selected) {
        _ImgV_showDetail.image = [UIImage imageNamed:@"bkmyorder_up"];
        _discountView.hidden = NO;
        [_discountView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_lab_payPrice.mas_bottom).offset(10);
            make.left.mas_equalTo(self.mas_left);
            make.height.mas_equalTo(@(height));
        }];
        
    }
    if (!_btn_showDetail.selected) {
        
        _ImgV_showDetail.image = [UIImage imageNamed:@"bkmyorder_down"];
        _discountView.hidden = YES;
    }
    
}
@end





